Questions
3 of 25
1How do you define a TypeORM entity and register it in a NestJS feature module?
2How do you handle TypeORM migrations in a NestJS project?
3How do you run a transaction with Prisma in NestJS?
4How do you perform CRUD operations and add query methods to a Mongoose model in NestJS?
5How do you use Prisma with multiple databases in a single NestJS application?
6What is the difference between find(), findOne(), findOneOrFail(), and the Query Builder in TypeORM?
7What are the two main ways to run a database transaction in TypeORM with NestJS?
8How do you handle Prisma migrations in a CI/CD pipeline?
9How do you add schema middleware (hooks) and instance methods in NestJS Mongoose?
10How do you mock a repository in a NestJS unit test?
11How do you seed a database in a NestJS application?
12How do you implement a Unit of Work pattern to group database operations across repositories in NestJS?
13How do you implement optimistic locking with TypeORM to prevent lost updates in NestJS?
14How do you integrate Prisma into a NestJS application?
15How do you implement soft deletes in NestJS with TypeORM?
16How do you implement multi-tenancy with a shared database in NestJS TypeORM?
17How do you set up TypeORM in a NestJS application?
18How do you implement a custom TypeORM repository in NestJS?
19How do you propagate a TypeORM transaction across multiple services in NestJS?
20What are Prisma middleware and how do you use them for audit logging in NestJS?
21How do you set up Mongoose in a NestJS application and define a schema?
22How do you handle Mongoose transactions for multi-document atomic operations in NestJS?
23What is the repository pattern and why use it in NestJS?
24How do you handle database connection pooling and health checks in NestJS?
25How do you implement database read replicas in NestJS for read/write splitting with TypeORM?
03 / 25

How do you run a transaction with Prisma in NestJS?

Use $transaction() with a callback for interactive transactions where each step depends on the previous result. Use the array form for sequential independent operations that must be atomic but do not reference each other's results. Pass isolationLevel and timeout options for fine-grained control.

Prisma interactive and sequential transactions
Prisma transaction patterns:
  1. 1

    Interactive transactions (callback) — use when each step depends on the result of a previous step.

  2. 2

    Sequential transactions (array) — use for truly independent operations that must commit or roll back together.

  3. 3

    In interactive transactions, always use the tx client — using this.prisma inside the callback bypasses the transaction.

  4. 4

    maxWait controls how long to wait for a connection; timeout controls the transaction duration limit.

  5. 5

    Nested interactive transactions are supported in Prisma 5+ via savepoints.

Difficulty: 5/10
Topics: Prisma transactions, NestJS request scope, Error handling

Scenario Questions

0-2 years experience
  1. 1

    We need to create an order and its line items in one API call. How would you use Prisma in a NestJS service to make sure both inserts succeed or both are rolled back?

  2. 2

    If you start a Prisma transaction but forget to await the promise, what would the NestJS request return and why?

  3. 3

    Show me how you would inject the Prisma client into a NestJS controller and begin a simple transaction.

2-5 years experience
  1. 1

    A feature updates a user's balance and writes a transaction record. Midway through, the balance update fails validation. How would you structure the code so the whole operation rolls back?

  2. 2

    During load testing, many concurrent requests start Prisma transactions and you see deadlocks. What strategies could you apply to reduce or avoid those deadlocks?

  3. 3

    You moved some logic into a separate NestJS service that calls an external microservice inside a Prisma transaction, and now the transaction fails. Why might that happen and how would you fix it?

5-8 years experience
  1. 1

    Design a pattern that lets multiple NestJS modules (Order, Inventory, Notification) share the same Prisma transaction context. What trade‑offs does your design have?

  2. 2

    How would you add retry logic for transient failures inside a Prisma transaction without causing duplicate writes?

  3. 3

    Discuss the performance and memory implications of using a request‑scoped PrismaService for transactions under high concurrency.

8+ years experience
  1. 1

    Our monolith is being split into several microservices, each with its own Prisma client. How would you migrate existing cross‑entity transactions to a distributed transaction model while preserving data integrity?

  2. 2

    At thousands of QPS, what architectural changes would you consider for transaction handling in NestJS with Prisma to avoid bottlenecks?

  3. 3

    How would you set up monitoring, alerting, and team policies for transaction failures across services that use Prisma?

Follow-up Questions

  • What happens if one of the queries inside the transaction throws an exception?
  • How does a request‑scoped PrismaService affect transaction lifecycle?
  • Can you compare the array‑based $transaction API with the interactive transaction callback?